﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Swift;

namespace CB.Logic
{
    public enum Direction
    {
        Left,
        Up,
        Down,
        Right,
        None,
    }

    public abstract class Block
    {
        public int X { get; set; }
        public int Y { get; set; }
        public bool IsEmpty = false;

        public void FindTargetBlock(out int tx, out int ty)
        {
            tx = X - 1;
            ty = Y - 1;
        }

        public void Left(out int tx, out int ty)
        {
            tx = X - 1;
            ty = Y;
        }

        public void Right(out int tx, out int ty)
        {
            tx = X + 1;
            ty = Y;
        }

        public void Up(out int tx, out int ty)
        {
            tx = X;
            ty = Y - 1;
        }

        public void Down(out int tx, out int ty)
        {
            tx = X;
            ty = Y + 1;
        }

        /// <summary>
        /// 目标方块的距离
        /// </summary>
        public int GetDistance(Block block)
        {
            return Math.Abs(X - block.X) + Math.Abs(Y - block.Y);
        }

        /// <summary>
        /// 目标方块的相对方向, 不相邻返回None
        /// </summary>
        public Direction GetDirection(Block block)
        {
            if (GetDistance(block) != 1)
                return Direction.None;

            if (X - block.X == 1)
                return Direction.Left;
            else if (X - block.X == -1)
                return Direction.Right;
            else if (Y - block.Y == 1)
                return Direction.Up;
            else
                return Direction.Down;
        }
    }

    public enum BColor
    {
        Red,
        Blue,
        Yellow,
        Black,
        Purple,
        Green,
        None,
    }

    public class ColorBlock : Block
    {
        public BColor BColor { get; set; }
    }

    public class ImageBlock : Block
    {
        public int TX { get; set; }
        public int TY { get; set; }
    }
}
